/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import org.hibernate.QueryException;
import org.hibernate.Session;
import org.hibernate.SessionException;
import org.hibernate.SessionFactory;
import pojo.Nhanvien;
import util.HibernateUtil;

/**
 *
 * @author Quan
 */
public class PhanQuyenDAO extends TableDAO {

    public PhanQuyenDAO() {
        hql_laydanhsach = "from Phanquyen";
        hql_lay = "from Phanquyen where id = :id";
    }

    public List LayQuyenCuaUser(Nhanvien id) throws Exception {
        List ds = null;
        SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
        Session session = sessionFactory.openSession();
        String hql = "from Phanquyen where nhanvien = :nhanvien";
        try {
            org.hibernate.Query query = session.createQuery(hql);
            query.setParameter("nhanvien", id);
            ds = query.list();
        } catch (SessionException e) {
            throw new QueryException(e.getMessage());
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        } finally {
            session.close();
        }
        return ds;
    }
}
